<?php

namespace App\Http\Controllers\Api\V1;

use App\Exceptions\Api\ApiInputErrorException;
use App\Http\Requests\Api\ApiRequest as Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str;

use Session;

class SessionController extends Controller
{

    /**
     * @api {post} /api/session 获取session_id
     * @apiName api/session
     * @apiGroup Session
     * @apiDescription 获取会话session_id
     * @apiParam {string} client_id  客户端ID   (IOS:be4f09b1d8789c176a2a3b5b4a168841;android:be4f09b1d8789c176a2a3b5b4a168841)
     * @apiParam {string} device_id  设备ID
     *
     * @apiSuccess {string}  session_id session_id
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
    {
    "session_id":,
    }
     */

    public function index(Request $request)
    {


        $cliet_id = $request->get('client_id');

        if ($cliet_id=='') throw new ApiInputErrorException('缺少client_id参数');

        $device_id = $request->get('device_id');

        //验证客户端
        $config = config('api.client');
        if (!key_exists($cliet_id,$config)){
            return response()->json(['error'=>'客户端不存在'],403);
        }

        $session_id =  $request->apiSession->makeToken();


        return response()->json(['session_id'=>$session_id]);

    }



}
